<template>
  <div class="mod-sys__menu">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item prop="generalArchiveList" label="全宗" class="role-list">
        <el-select placeholder="请选择所属全宗" v-model="dataForm.archiveId">
          <el-option v-for="generalArchive in generalArchiveList" :key="generalArchive.id" :label="generalArchive.name" :value="generalArchive.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="档案类型名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" row-key="id" border style="width: 100%">
      <el-table-column prop="name" label="门类名称" header-align="center" min-width="150"></el-table-column>
      <el-table-column prop="code" label="门类编码" header-align="center" align="center"></el-table-column>
      <el-table-column prop="archiveAreaDesc" label="归档范围" header-align="center" align="center"></el-table-column>
      <el-table-column prop="deadLineStr" label="保管期限" header-align="center" align="center"></el-table-column>
      <el-table-column prop="secretStr" label="密级" header-align="center" align="center"></el-table-column>
      <el-table-column prop="typeStr" label="级别" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('archive:class:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('archive:class:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import baseService from "@/service/baseService";
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./category-add.vue";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/archive/class/list",
      deleteURL: "/archive/class/",
      generalArchiveList: [],
      generalArchiveName: "",
      dataForm: {
        archiveId: "",
        name: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created() {
    baseService.get(`/archive/info/list`).then((res) => {
      if (res.code !== 0) {
        return this.$message.error(res.msg);
      }
      this.generalArchiveList = res.data;
    });
  },
  methods: {}
});
</script>
